#!/bin/sh


#
# Define vars
#
CLIENT=../p2_client/ibrc_client
SLEEP_TIME=0.1

FOLDER=/tmp/ibrc/

mkdir -p $FOLDER

#rm -f $FOLDER/ibrc_*.log

###################################
#
# Start and connect clients
#
###################################

sleep $SLEEP_TIME

$CLIENT -p 5000 -in $FOLDER/ibrc_client00.input -out $FOLDER/ibrc_client00.out -l $FOLDER/ibrc_client00.log &
$CLIENT -p 5001 -in $FOLDER/ibrc_client10.input -out $FOLDER/ibrc_client10.out -l $FOLDER/ibrc_client10.log &
$CLIENT -p 5002 -in $FOLDER/ibrc_client20.input -out $FOLDER/ibrc_client20.out -l $FOLDER/ibrc_client20.log &
$CLIENT -p 5003 -in $FOLDER/ibrc_client30.input -out $FOLDER/ibrc_client30.out -l $FOLDER/ibrc_client30.log &
$CLIENT -p 5004 -in $FOLDER/ibrc_client40.input -out $FOLDER/ibrc_client40.out -l $FOLDER/ibrc_client40.log &
$CLIENT -p 5005 -in $FOLDER/ibrc_client50.input -out $FOLDER/ibrc_client50.out -l $FOLDER/ibrc_client50.log &
$CLIENT -p 5006 -in $FOLDER/ibrc_client60.input -out $FOLDER/ibrc_client60.out -l $FOLDER/ibrc_client60.log &
$CLIENT -p 5007 -in $FOLDER/ibrc_client70.input -out $FOLDER/ibrc_client70.out -l $FOLDER/ibrc_client70.log &

$CLIENT -p 5000 -in $FOLDER/ibrc_client01.input -out $FOLDER/ibrc_client01.out -l $FOLDER/ibrc_client01.log &
$CLIENT -p 5001 -in $FOLDER/ibrc_client11.input -out $FOLDER/ibrc_client11.out -l $FOLDER/ibrc_client11.log &
$CLIENT -p 5002 -in $FOLDER/ibrc_client21.input -out $FOLDER/ibrc_client21.out -l $FOLDER/ibrc_client21.log &
$CLIENT -p 5003 -in $FOLDER/ibrc_client31.input -out $FOLDER/ibrc_client31.out -l $FOLDER/ibrc_client31.log &
$CLIENT -p 5004 -in $FOLDER/ibrc_client41.input -out $FOLDER/ibrc_client41.out -l $FOLDER/ibrc_client41.log &
$CLIENT -p 5005 -in $FOLDER/ibrc_client51.input -out $FOLDER/ibrc_client51.out -l $FOLDER/ibrc_client51.log &
$CLIENT -p 5006 -in $FOLDER/ibrc_client61.input -out $FOLDER/ibrc_client61.out -l $FOLDER/ibrc_client61.log &
$CLIENT -p 5007 -in $FOLDER/ibrc_client71.input -out $FOLDER/ibrc_client71.out -l $FOLDER/ibrc_client71.log &

sleep 1


###################################
#
# Request new nicknames
#
###################################

echo "\NICK client0 " >> $FOLDER/ibrc_client00.input
echo "\NICK client0 " >> $FOLDER/ibrc_client10.input
echo "\NICK client0 " >> $FOLDER/ibrc_client20.input
echo "\NICK client0 " >> $FOLDER/ibrc_client30.input
echo "\NICK client0 " >> $FOLDER/ibrc_client40.input
echo "\NICK client0 " >> $FOLDER/ibrc_client50.input
echo "\NICK client0 " >> $FOLDER/ibrc_client60.input
echo "\NICK client0 " >> $FOLDER/ibrc_client70.input

echo "\NICK client1 " >> $FOLDER/ibrc_client01.input
echo "\NICK client1 " >> $FOLDER/ibrc_client11.input
echo "\NICK client1 " >> $FOLDER/ibrc_client21.input
echo "\NICK client1 " >> $FOLDER/ibrc_client31.input
echo "\NICK client1 " >> $FOLDER/ibrc_client41.input
echo "\NICK client1 " >> $FOLDER/ibrc_client51.input
echo "\NICK client1 " >> $FOLDER/ibrc_client61.input
echo "\NICK client1 " >> $FOLDER/ibrc_client71.input

sleep 1




###################################
#
# Join Channels
#
###################################

echo "\JOIN testchannel0 " >> $FOLDER/ibrc_client00.input
sleep 0.1
echo "\JOIN testchannel0 " >> $FOLDER/ibrc_client10.input
echo "\JOIN testchannel0 " >> $FOLDER/ibrc_client20.input
echo "\JOIN testchannel0 " >> $FOLDER/ibrc_client30.input
echo "\JOIN testchannel0 " >> $FOLDER/ibrc_client40.input
echo "\JOIN testchannel0 " >> $FOLDER/ibrc_client50.input
echo "\JOIN testchannel0 " >> $FOLDER/ibrc_client60.input
echo "\JOIN testchannel0 " >> $FOLDER/ibrc_client70.input

echo "\JOIN testchannel1 " >> $FOLDER/ibrc_client01.input
sleep 0.1
echo "\JOIN testchannel1 " >> $FOLDER/ibrc_client11.input
echo "\JOIN testchannel1 " >> $FOLDER/ibrc_client21.input
echo "\JOIN testchannel1 " >> $FOLDER/ibrc_client31.input
echo "\JOIN testchannel1 " >> $FOLDER/ibrc_client41.input
echo "\JOIN testchannel1 " >> $FOLDER/ibrc_client51.input
echo "\JOIN testchannel1 " >> $FOLDER/ibrc_client61.input
echo "\JOIN testchannel1 " >> $FOLDER/ibrc_client71.input





###################################
#
# Set channel topics
#
###################################

echo "\SETTOPIC A testchannel called testchannel0 " >> $FOLDER/ibrc_client00.input
echo "\SETTOPIC A testchannel called testchannel1 " >> $FOLDER/ibrc_client01.input
sleep 0.1

echo "\GETTOPIC " >> $FOLDER/ibrc_client00.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client10.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client20.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client30.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client40.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client50.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client60.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client70.input

echo "\GETTOPIC " >> $FOLDER/ibrc_client01.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client11.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client21.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client31.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client41.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client51.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client61.input
echo "\GETTOPIC " >> $FOLDER/ibrc_client71.input
